# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=tiny
pkgver=0.12.0
pkgrel=0
pkgdesc="Terminal IRC client written in Rust"
url="https://github.com/osa1/tiny"
# s390x: fails to build due to nix crate
arch="all !s390x"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	openssl-dev
	"
subpackages="$pkgname-doc"
source="https://github.com/osa1/tiny/archive/v$pkgver/tiny-$pkgver.tar.gz
	update-cargo-lock.patch
	nix-crate-loongarch64_patch
	"

_cargo_opts="--frozen --no-default-features --features=tls-native"

# taken from main/rust/APKBUILD
_clear_vendor_checksums() {
	sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}

prepare() {
	default_prepare

	cargo vendor --locked

	_clear_vendor_checksums nix
	patch vendor/nix/src/sys/ioctl/linux.rs \
		"$srcdir"/nix-crate-loongarch64_patch

	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[source.crates-io]
		replace-with = "vendored-sources"

		[source.vendored-sources]
		directory = "vendor"
	EOF
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -Dvm755 target/release/tiny -t "$pkgdir"/usr/bin/

	install -Dvm644 README.md -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dvm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}

sha512sums="
59822399408760a5120203f3d8e82a0144cbed462a93b915bf812f943acaaab6ead988fd016c9e20e095d0b4338ad226c3bad31b4533dcb18591996b7fe4b404  tiny-0.12.0.tar.gz
9c27793f1bf594ab2d5c2be77ffb901307eed4c09b2c0beff9058760a1217faa206e91fecbc9229aadd0e1b46c2ef1ce9964d85d9b6ec58754716b6f577df1d8  update-cargo-lock.patch
14ffe9ec16139856f428c52d19c3b03fbcc1e10c23aff2bf33679f46552d089f6ee1fae968ceeeb691cff757d55ac631d9d6040780bd8c2a99cdff75df8f3a67  nix-crate-loongarch64_patch
"
